/**
* Created by Felix
* 06/29/2007
*/
jsx3.require("jsx3.gui.Dialog");
jsx3.lang.Class.defineClass(
"tibco.admin.monitormanage.wsdlGen.WsdlGen",
jsx3.gui.Dialog,
null,
function (plugin) {
    /*plugin.prototype.btnSave_onclick = function() {
        //open dialog if necessary
        if ((dialog = tibco.admin.Main.getServer().getJSXByName("jsxdialog")) == null)
            dialog = jsx3.addins.FileDialog.deserialize(APP.tibco.admin.getBodyBlock(),"jsxdialog");

        var me = this;
        //bind callback and show
        dialog.onExecute = function(file) {
            if (document.implementation && document.implementation.createDocument)  {
						    file.write(me.getDescendantOfName("txtWSDL").getValue(), "utf-16", "dos", true);
						} else {
						    file.write(me.getDescendantOfName("txtWSDL").getValue(), true);
						}
						jsx3.log("Saved Successfully!");
        };

        var openPath = jsx3.app.Browser.getSystem() == jsx3.app.Browser.WIN32 ? "c:\\" : "/";
        dialog.openForSave(openPath);
    }
    */

    //call this method to begin the service call (eg.service.callgenerateWSDL();)
    plugin.prototype.callgenerateWSDL = function() {
        var objService = tibco.admin.Main.loadService("tibco.admin",
            "tibco/admin/monitormanage/wsdlGen/rules/generateWSDL.xml",
            "generateWSDL",
            "generateWSDL");
        //subscribe and call
        objService.nodeId = this.serviceId;
        objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.ongenerateWSDLSuccess);
        objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.ongenerateWSDLError);
        objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.ongenerateWSDLInvalid);
        if(tibco.admin.Main.getServer().getEnv("MODE")) {
            objService.setEndpointURL(tibco.admin.util.ServiceHelper.getMonitorAndManageEndpointURL());
        }
        objService.doCall();
    };

    plugin.prototype.ongenerateWSDLSuccess = function(objEvent) {
        this.WSDLurl = objEvent.target.url;
    };

    plugin.prototype.ongenerateWSDLError = function(objEvent) {
    };

    plugin.prototype.ongenerateWSDLInvalid = function(objEvent) {
    };
    
    plugin.prototype.downloadFile = function() {
        if(this.WSDLurl) {
            window.open(this.WSDLurl);
        }
    }
});